package com.beiing.tianshuai.tianshuai.mine.presenter;

import com.beiing.tianshuai.tianshuai.mine.entity.OrderUserAddressDataBean;
import com.beiing.tianshuai.tianshuai.mine.entity.OrderUserAddressDefaultDataBean;
import com.beiing.tianshuai.tianshuai.mine.entity.OrderUserAddressDeleteDataBean;
import com.beiing.tianshuai.tianshuai.mine.model.OrderAddressManageModel;
import com.beiing.tianshuai.tianshuai.mine.model.OrderAddressManageModelImpl;
import com.beiing.tianshuai.tianshuai.mine.view.OrderAddressManageViewImpl;

/**
 * Created by Administrator on 2018/4/10.
 * 订单地址信息管理层，进行订单查询，默认地址修改，删除等3个数据请求管理
 */

public class OrderAddressManagePresenter implements OrderAddressManagePresenterImpl,
        OrderAddressManageModel.OrderUserAddressDataResponseListener,
        OrderAddressManageModel.OrderUserAddressDefaultDataResponseListener,
        OrderAddressManageModel.OrderUserAddressDeleteDataResponseListener{

    private OrderAddressManageViewImpl mView;
    private OrderAddressManageModelImpl mModel;

    public OrderAddressManagePresenter(OrderAddressManageViewImpl view) {
        mView = view;
        mModel = new OrderAddressManageModel(this,this,this);
    }

    /**
     * 获取用户地址列表
     * @param userId 用户id
     */
    @Override
    public void getUserAddress(String userId) {
        mView.showProgress();
        mModel.getUserAddress(userId);
    }

    /**
     * 设置用户默认地址
     * @param userId 用户id
     * @param addressId 地址id
     */
    @Override
    public void getUserAddressDef(String userId, String addressId,OrderUserAddressDataBean.DataBean.AddressBean changeBean,
                                  OrderUserAddressDataBean.DataBean.AddressBean changeAfterBean) {
        mView.showProgress();
        mModel.getUserAddressDef(userId,addressId,changeBean,changeAfterBean);
    }

    /**
     * 删除用户地址
     * @param addressId 地址id
     * @param position 位置
     */
    @Override
    public void getUserAddressDel(String addressId, int position) {
        mView.showProgress();
        mModel.getUserAddressDel(addressId, position);
    }


    @Override
    public void onGetDetailSuccess(OrderUserAddressDataBean bean) {
       //请求成功返回
        mView.hideProgress();
        mView.getOrderInformationAddressSuccess(bean);
    }

    @Override
    public void onGetDetailError(Throwable throwable) {

    }

    @Override
    public void onGetDetailSuccessDefault(OrderUserAddressDefaultDataBean bean,OrderUserAddressDataBean.DataBean.AddressBean changeBean,
                                          OrderUserAddressDataBean.DataBean.AddressBean changeAfterBean) {
         //请求成功返回
        mView.hideProgress();
        mView.getOrderDefaultInformationSuccess(bean,changeBean,changeAfterBean);
    }

    @Override
    public void onGetDetailErrorDefault(Throwable throwable) {

    }

    @Override
    public void onDeleteSuccess(OrderUserAddressDeleteDataBean bean, int position) {
        mView.hideProgress();
        mView.onDeleteSuccess(bean, position);
    }

    @Override
    public void onDeleteError(Throwable throwable) {

    }
}
